//
//  UIView+HUD.m
//  PuHuiJia
//
//  Created by wang.songguo on 15/12/15.
//  Copyright © 2015年 puxin. All rights reserved.
//

#import "UIView+HUD.h"
#import <MBProgressHUD/MBProgressHUD.h>

@implementation UIView (HUD)

- (void)showHUDWithTitle:(NSString *)title
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self animated:YES];
    
    hud.mode = MBProgressHUDModeText;
    
    hud.label.numberOfLines = 0;
    
    hud.contentColor = [UIColor whiteColor];
    
    hud.bezelView.backgroundColor = [UIColor blackColor];
    
    hud.label.text = title;
    
    hud.margin = 10.f;

    hud.removeFromSuperViewOnHide = YES;
    
    [hud hideAnimated:YES afterDelay:2];
}

- (void)showHUD
{
    MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self];
    
    [self addSubview:hud];
    
    [hud showAnimated:YES];
}

- (void)hideHUD
{
    MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self];
    
    [hud hideAnimated:YES];
}

- (void)showHUDWithTitle:(NSString *)title WhileExcuteBlock:(myBlock)myBlock
{
    MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self];
    [self addSubview:hud];
    hud.label.text = title;
    
    [hud showAnimated:YES whileExecutingBlock:^{
        myBlock();
    } completionBlock:^{
        [hud removeFromSuperview];
    }];
}

@end
